﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using TinyCinema.Data;
using System.Windows.Input;
using System.Windows.Controls;
using System.Collections.ObjectModel;

namespace Reports.Customer
{
    public class Report1 : DependencyObject
    {
        public static DependencyProperty CustomerTypeProperty = DependencyProperty.Register("CustomerType", typeof(TinyCinema.Data.CustomerType), typeof(Report1));
        public TinyCinema.Data.CustomerType CustomerType
        {
            get { return (TinyCinema.Data.CustomerType)GetValue(CustomerTypeProperty); }
            set
            {
                SetValue(CustomerTypeProperty, value);
            }
        }
        public static DependencyProperty lstCustomerTypeProperty = DependencyProperty.Register("lstCustomerType", typeof(ObservableCollection<TinyCinema.Data.CustomerType>), typeof(Report1));
        public ObservableCollection<TinyCinema.Data.CustomerType> lstCustomerType
        {
            get { return (ObservableCollection<TinyCinema.Data.CustomerType>)GetValue(lstCustomerTypeProperty); }
            set { SetValue(lstCustomerTypeProperty, value); }
        }
        
        public Report1()
        {
            lstCustomerType = CustomerType.getAllCustomerType();
            lstCustomerType.RemoveAt(0);
        }
        public CrystalReport1 Load(TinyCinema.Bussiness.Login.Employee LoginInfo)
        {
            string sql;
            CrystalReport1 report = new CrystalReport1();
            if (CustomerType == null)
            {
                sql = "select  KHACHHANG.TenKH, KHACHHANG.GioiTinh, KHACHHANG.NgaySinh, KHACHHANG.DienThoai, KHACHHANG.NgayDangKy, KHACHHANG.Diem"
                           + " from KHACHHANG"
                           + " where KHACHHANG.MaLKH='" + lstCustomerType[0].ID + "'"
                           + " order by KHACHHANG.TenKH";                
                report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
                report.SetParameterValue("CustomerType", lstCustomerType[0].Name.ToUpper());
            }
            else
            {
                sql = "select  KHACHHANG.TenKH, KHACHHANG.GioiTinh, KHACHHANG.NgaySinh, KHACHHANG.DienThoai, KHACHHANG.NgayDangKy, KHACHHANG.Diem"
                        + " from KHACHHANG"
                         + " where KHACHHANG.MaLKH='" + CustomerType.ID + "'"
                        + " order by KHACHHANG.TenKH";
                report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
                report.SetParameterValue("CustomerType", CustomerType.Name.ToUpper());
            }
            report.SetParameterValue("EmployeeName", LoginInfo.Emp.Name);
            return report;
            
        }
    }
}
